# 导包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ActionChains

# 打开浏览器
service = Service(r"D://Python314//chromedriver.exe")
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 2.输入访问地址（URL）
# driver.get("http://121.43.169.97:8848/pageA.html")
# 2.输入访问地址（URL）
url = r"D:\pythonProject\pythonProject1\demo.html"
driver.get(url)
# 放大游览器页面
# driver.maximize_window()

# 实例化ActionChains获取元素
action = ActionChains(driver)

# 获取 源元素
source = driver.find_element(By.CSS_SELECTOR,"#div1")
# 获取 目标元素
target = driver.find_element(By.CSS_SELECTOR,"#div2")
time.sleep(3)
action.drag_and_drop(source, target).perform()
# 扩展 通过坐标偏移量执行
time.sleep(3)
action.drag_and_drop_by_offset(source,xoffset=300,yoffset=300).perform()


